unit uDiag_IpRange;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ToolWin, ComCtrls, Buttons, Vcl.Mask, synaip;

type
  TDiag_IpRange_F = class(TForm)
    ToolBar3: TToolBar;
    Label31: TLabel;
    Info_Pesquisa: TToolBar;
    btnOK: TSpeedButton;
    btnCancel: TSpeedButton;
    mskInicio: TMaskEdit;
    Label1: TLabel;
    mskFinal: TMaskEdit;
    Label2: TLabel;
    btOK: TButton;
    procedure mskInicioEnter(Sender: TObject);
    procedure mskFinalEnter(Sender: TObject);
    procedure mskFinalExit(Sender: TObject);
    procedure mskInicioExit(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Diag_IpRange_F: TDiag_IpRange_F;

implementation

{$R *.dfm}

uses gVars_u;

procedure TDiag_IpRange_F.btnCancelClick(Sender: TObject);
begin
   Self.ModalResult := mrCancel;
end;

procedure TDiag_IpRange_F.btnOKClick(Sender: TObject);
begin

 vgFiltro.IP_Inicial := mskInicio.Text;
 vgFiltro.IP_Final   := mskFinal.Text;



  if not IsIP( vgFiltro.IP_Inicial ) then
    Begin
      mskInicio.SetFocus;
      exit;
    End;
  if not IsIP( vgFiltro.IP_Final ) then
    Begin
      mskFinal.SetFocus;
      exit;
    End;

  Self.ModalResult := mrOk;
end;

procedure TDiag_IpRange_F.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  Diag_IpRange_F := Nil;
end;

procedure TDiag_IpRange_F.FormCreate(Sender: TObject);
begin
  mskInicio.Text := vgFiltro.IP_Inicial;
  mskFinal.Text  := vgFiltro.IP_Final;
end;

procedure TDiag_IpRange_F.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key = vk_return then
    SelectNext(ActiveControl,True,True);

  if key = vk_prior then
    SelectNext(ActiveControl,False,True);

end;

procedure TDiag_IpRange_F.mskInicioEnter(Sender: TObject);
begin
 (Sender as TMaskEdit).Text := vgFiltro.IP_Inicial;
end;

procedure TDiag_IpRange_F.mskInicioExit(Sender: TObject);
begin
  vgFiltro.IP_Inicial  := (Sender as TMaskEdit).Text;
end;

procedure TDiag_IpRange_F.mskFinalEnter(Sender: TObject);
begin
 (Sender as TMaskEdit).Text := vgFiltro.IP_Final;
end;

procedure TDiag_IpRange_F.mskFinalExit(Sender: TObject);
begin
  vgFiltro.IP_Final  := (Sender as TMaskEdit).Text;
end;

end.
